<!--子页面-->
<?php
use yii\widgets\LinkPager;
?>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>帐号管理</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group form-horizontal form-style">
                        <div class="row m-b">
                            <label class="col-sm-1 control-label">帐号</label>
                            <div class="col-sm-2">
                                <input type="text" name="username" class="form-control username" value="<?php echo !empty($data['username'])?$data['username']:'';?>">
                            </div>
                            <label class="col-sm-2 control-label">手机号码</label>
                            <div class="col-sm-2">
                                <input type="text" name="mobile" class="form-control mobile" value="<?php echo !empty($data['mobile'])?$data['mobile']:'';?>">
                            </div>
                            <div class="col-sm-2">
                                <button type="button" class="btn  btn-primary slecctform">搜索</button>
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-horizontal form-style">
                        <?php if($this->context->isAuth('admin/add')){?>
                            <a class="btn btn-primary" href="<?= yii\helpers\Url::to(['admin/add'])?>">新建用户</a>
                        <?php }?>
                    </div>
                    <?php if(!empty($model)){?>
                        <table class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                            <tr class="tb-title">
                                <th class="text-center">ID</th>
                                <th class="text-center">帐号</th>
                                <th class="text-center">手机号码</th>
                                <th class="text-center">工号</th>
                                <th class="text-center">性别</th>
                                <th class="text-center">账户类型</th>
                                <th class="text-center">创建者</th>
                                <th class="text-center">状态</th>
                                <th class="text-center">角色</th>
                                <th class="text-center">创建时间</th>
                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($model as $k=>$v){?>
                                <tr align="center" data-id="<?php echo $v['id'];?>">
                                    <td><?php echo $v['id'];?></td>
                                    <td><?php echo !empty($v['name']) ? $v['name'] : '-';?></td>
                                    <td><?php echo !empty($v['mobile']) ? $v['mobile'] : '-';?></td>
                                    <td><?php echo !empty($v['job_number']) ? $v['job_number'] : '-';?></td>
                                    <td><?= $v['sex'] == 1?'男':($v['sex'] == 2 ?'女':'-') ?></td>
                                    <td><?= Yii::$app->params['account_type'][$v['account_type']]?></td>
                                    <td><?php echo !empty($v['creator']) ? $v['creator'] : '-';?></td>
                                    <td>
                                        <?php if($this->context->isAuth('admin/status-ajax-do')){?>
                                            <?= $v['status'] == 1?'<a href="javascript:;" class="btn btn-xs btn-primary ajax_action" data-status="2" tip="禁用" url="status-ajax-do">正常</a>':
                                                ($v['status'] == 2?'<a href="javascript:;" class="btn btn-xs btn-warning ajax_action" data-status="1" tip="解禁" url="status-ajax-do">禁用</a>':
                                                '<a href="javascript:;" class="btn btn-xs btn-warning ajax_action" data-status="1" tip="重新启用" url="status-ajax-do">删除</a>')?>
                                        <?php }else{?>
                                            <?= $v['status'] == 1 ? '正常':($v['status'] == 2 ?'禁用' : '删除') ?>
                                        <?php }?>
                                    </td>
                                    <td><?php echo $v['id'] == 1?'超级管理员':$v['role_name']?></td>
                                    <td><?php echo !empty($v['create_time']) ? date("Y-m-d", $v['create_time']) : '-';?></td>
                                    <td>
                                        <input type="hidden" class="user_id" value="<?php echo $v['id']?>">
                                        <?php if($this->context->isAuth('admin/edit')){?><a class="btn btn-xs btn-primary" href="<?= yii\helpers\Url::toRoute(['admin/edit', 'id' => $v['id']])?>">编辑</a><?php }?>
                                        <?php if($v['id'] != 1){?>
                                            <?php if($this->context->isAuth('admin/reset-password-ajax-do')){?><a class="btn btn-xs btn-primary reset-pwd" href="javascript:;">重置密码</a><?php }?>
                                        <?php }?>
                                    </td>
                                </tr>
                            <?php }?>
                            </tbody>
                        </table>
                    <?php }else{?>
                        <div align="center" style="color: red">
                            暂无数据
                        </div>
                    <?php }?>
                    <div class="row">
                        <div class="col-sm-12  form-inline text-right">
                            <div class="btn-group" align="center">
                                <?= LinkPager::widget(['pagination' => $pagination, 'options'=>['class'=>'page-num'],'firstPageLabel' =>'首页','lastPageLabel'=>'尾页']); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal inmodal" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                </button>
                <h6 class="modal-title">重置密码</h6>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="ibox float-e-margins">
                            <div class="form-horizontal">
                                <div class="form-group">
                                    <label class="col-sm-4 control-label"><span class="text-danger">*</span>密码：</label>
                                    <div class="col-sm-6">
                                        <input type="password" class="form-control" name="password" id="password">
                                        <input type="hidden" id="id">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary addclass" data-dismiss="modal">保存</button>
            </div>
        </div>
    </div>
</div>
<!-- 日历 -->
<!--js-->
<script src="/js/plugins/layer/laydate/laydate.js" type="text/javascript"></script>
<script type="text/javascript">
$(".slecctform").click(function(){
    var str = "1=1";
    var username = $(".username").val();
    var mobile = $(".mobile").val();
    if(username.length >= 0){
        str += "&name="+username;
    }
    if(mobile.length >= 0){
        str += "&mobile="+mobile;
    }
    window.location.href='list?'+str;
});

//删除确认
$('.demo1').click(function () {
    var id = $(this).siblings(".user_id").val();
    swal({
        title: "您确定要删除该帐号吗？",
        text: "该操作很重要，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "删除",
        cancelButtonText: "让我再考虑一下…",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function (isConfirm) {
        if (isConfirm) {
            $.ajax({
                type: "post",
                    url: "dele-ajax-do",
                    data: {id:id},
                    dataType: "json",
                    success: function(param){
                    if(param.code == '20000'){
                        swal("删除成功！", param.message, "success");
                        location.reload();
                    }else{
                        swal("删除失败！", param.message, "error")
                    }
                  }
            });
        } else {
            swal("已取消", "您取消了删除操作！", "error")
        }
    });
});

$('.reset-pwd').click(function(){
    var id = $(this).siblings(".user_id").val();
    $("#password").val('');
    $("#id").val(id);
    $('#myModal1').modal('show');
});
$(".addclass").click(function(){
    var id = $("#id").val();
    var password = $("#password").val();
    $.ajax({
        type: "post",
        url: "reset-password-ajax-do",
        data: {id:id,password:password},
        dataType: "json",
        success: function(param){
            if(param.code == '20000'){
                alert(param.message);
                location.reload();
            }else{
                alert(param.message);
            }
        }
    });
});
</script>
<!--js-->
<!--/子页面-->


